package com.ljxt.dt.web.servlet.basicinformationservlet;

import com.ljxt.dt.domain.GoodsInfo;
import com.ljxt.dt.domain.SupplierType;
import com.ljxt.dt.service.basicinformationservice.SupplierListService;
import com.ljxt.dt.service.basicinformationservice.impl.SupplierListServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 糖糖
 * @version 1.0.0
 * @date 2020/5/11 22:06
 * @copyright 老九学堂
 */
@WebServlet("/addNewSupplier.html")
public class AddNewSupplierServlet extends HttpServlet {

    private SupplierListService supplierListService = new SupplierListServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(11212);
        //查询供应商的类型
        List<SupplierType> supplierTypeList = supplierListService.selectSupplierType();

        //将集合保存在请求中
        req.setAttribute("typeList", supplierTypeList);
        req.getRequestDispatcher("WEB-INF/views/basicinformation/addNewSupplier.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println(22222);
        //1.获取供应商基础参数
        String typeId = req.getParameter("typeId");
        String typeName = req.getParameter("supplierName");
        String pro = req.getParameter("pro");
        String city = req.getParameter("city");
        String dis = req.getParameter("district");
        String detailAddress = req.getParameter("detailAddress");
        //2.获取联系人基本信息
        String contactName = req.getParameter("contactName");
        String phone = req.getParameter("phone");
        //获取供应商物品信息
        String[] goodsIdArray = req.getParameterValues("goodsIdArray");
        //将地址拼接成完整地址
        String address = pro+"-"+city+"-"+dis+"-"+detailAddress;

        //调用方法实现新增供应商
        boolean success = supplierListService.addNewSupplier(Integer.parseInt(typeId), typeName, address, contactName, phone, goodsIdArray);
        System.out.println("success = " + success);
    }
}
